package com.sys.mapper;

import com.sys.entity.BizAbilityScore;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface BizAbilityScoreMapper {
    @Insert("INSERT INTO biz_ability_score (user_id, domain, score_decimal, score_date, source, create_by, create_time, del_flag) " +
            "VALUES (#{userId}, #{domain}, #{scoreDecimal}, #{scoreDate}, #{source}, #{createBy}, #{createTime}, COALESCE(#{delFlag}, 0))")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void save(BizAbilityScore score);

    @Select("SELECT * FROM biz_ability_score " +
            "WHERE user_id = #{userId} " +
            "AND (#{domain} IS NULL OR domain = #{domain}) " +
            "AND score_date BETWEEN #{startDate} AND #{endDate} " +
            "AND del_flag = 0 " +
            "ORDER BY score_date ASC")
    List<BizAbilityScore> findByUserIdAndDomainAndDateRange(@Param("userId") Long userId,
            @Param("domain") String domain,
            @Param("startDate") LocalDate startDate,
            @Param("endDate") LocalDate endDate);
}